/**
 * @description 目标接口
 */
export interface IUserInfo {
  getUserName(): string
  getHomeAddress(): string
  getMobileNumber(): string
  getOfficeTelNumber(): string
  getJobPosition(): string
  getHomeTelNumber(): string
}

/**
 * @description 源接口
 */
export interface IOuterUser {
  getUserBaseInfo(): any
  getUserOfficeInfo(): any
  getUserHomeInfo(): any
}

class UserInfo implements IUserInfo {
  getUserName(): string {
    console.log('userName');
    return 'userName'
  }
  getHomeAddress(): string {
    console.log('homeAddress');
    return 'homeAddress'
  }
  getMobileNumber(): string {
    console.log('mobileNumber');
    return 'mobileNumber'
  }
  getOfficeTelNumber(): string {
    console.log('officeTelNumber');
    return 'officeTelNumber'
  }
  getJobPosition(): string {
    console.log('jobPosition');
    return 'jobPosition'
  }
  getHomeTelNumber(): string {
    console.log('homeTelNumber');
    return 'homeTelNumber'
  }
}

export interface IUserBaseInfo { userName: string, mobileNumber: string }
export interface IUserOfficeInfo { officeTelNumber: string, jobPosition: string }
export interface IUserHomeInfo { homeTelNumber: string, homeAddress: string }

class OuterUser implements IOuterUser {
  getUserBaseInfo(): IUserBaseInfo {
    return {
      userName: 'outUserName',
      mobileNumber: 'outMobileNumber'
    }
  }
  getUserOfficeInfo(): IUserOfficeInfo {
    return {
      officeTelNumber: 'outOfficeTelNumber',
      jobPosition: 'outJobPosition'
    }
  }
  getUserHomeInfo(): IUserHomeInfo {
    return {
      homeTelNumber: 'outHomeTelNumber',
      homeAddress: 'outHomeAddress'
    }
  }
}

/**
 * @description 适配器角色 继承源类，实现现有类
 */
class OuterUserInfo extends OuterUser implements IUserInfo {
  constructor() {
    super()
  }
  getUserName(): string {
    console.log(this.getUserBaseInfo().userName);
    return this.getUserBaseInfo().userName
  }
  getHomeAddress(): string {
    console.log(this.getUserHomeInfo().homeAddress);
    return this.getUserHomeInfo().homeAddress
  }
  getMobileNumber(): string {
    console.log(this.getUserBaseInfo().mobileNumber);
    return this.getUserBaseInfo().mobileNumber
  }
  getOfficeTelNumber(): string {
    console.log(this.getUserOfficeInfo().officeTelNumber);
    return this.getUserOfficeInfo().officeTelNumber
  }
  getJobPosition(): string {
    console.log(this.getUserOfficeInfo().jobPosition);
    return this.getUserOfficeInfo().jobPosition
  }
  getHomeTelNumber(): string {
    console.log(this.getUserHomeInfo().homeTelNumber);
    return this.getUserHomeInfo().homeTelNumber
  }
}

function main() {
  // 获取已经实现的用户信息
  const userInfo = new UserInfo()
  userInfo.getUserName()

  // 想获取外部的用户信息，但还是现在的方式
  const outerUserInfo = new OuterUserInfo()
  outerUserInfo.getUserName()
}
main()